pp108 : Model (Objects)

Model (Objects)

 

The Model property is the part of an XForms object model that holds real-time business objects. The Model object,

  • Uses the instance object to communicate and transact with services.
  • Sends requests to a service and holds the response.
  • Exploits the cursor facility provided by Process Platform processors for increased efficiency.
  • Creates and maintains the transaction state of the object.
  • Exposes APIs to manipulate business objects, or to provide event handlers.

    The model is represented directly in the MVC model. It is automatically created by the designer, when you use a method in the designer pane. You can create a model manually.

Creating a Model During Run Time


A model can be created using the getModel() method available for the WebForm object.

Transactional and Non-Transactional Models


Models are either transactional and non-transactional. Transactional models follow the Process Platform tuple protocol. For such models, the transaction (insertion, deletion, and update) is done automatically. In the case of non-Cordys, protocol-based messages, or when a complex XML must be handled, the non-transactional model is used.

Instance Schema

For models that have WSDL (with schema), the XForms client, by default, provides validation based on the reference that you provide. However, for models that do not have a schema, you need to provide the reference explicitly (you must also know the response in this case). Therefore, for models that do not have WSDL (and schema), it is possible to provide schema in the instance editor of XForms and you can provide the reference accordingly.

  • Transaction Models - For transactional models that have WSDL (with schema), XForms displays the schema definition in the instance editor, in read-only mode. This enables you to easily provide references for complex models. However, where the model does not have WSDL (with schema), it is possible to define a schema, and XForms client provides validation to the elements or controls, depending on the reference that you provide.
  • Non-Transactional Models - In case of non-transactional models that do not have WSDL (with schema), you can provide schema in an instance editor, and XForms client provides validation to the elements or controls, based on the reference that you provide.

    Note:XForms will not resolve externals of schema provided in instance editor.

    Navigation in Model


XForms renders business objects in the browser. Since the underlying architecture is service-oriented, messaging and rendering reduce the rendering and transportation latency.

A way of reducing the transportation latency is by using the generic cursor facility provided by the Process Platform services. Since the Process Platform cursor service provides functionality for only moving forward, two separate requests must be used for moving forward and backwards in a set of records. Apart from moving forward and backward, an object can also be located in a table.

TheBuilderfunction in Process Platform Ajax Toolkit can be used to generate these methods automatically for a given data source.

The request that is used for moving forward in the ascending order is callednext. This request must be modeled to consider all parameters and to retrieve all objects greater than the given parameters, in an ascending order. It is important that the order of the retrieved objects also uses the parameters.

The Employees table in the Northwind database of Microsoft SQL Server can be taken as an example. The following is the default implementation of the GetNextExployeesObjects method that retrieves the next set of records.

<implementation type="DBSQL" xmlns="">
    <constructor language="DBSQL">
        <query>select * from Employees where (EmployeeID&amp;gt;:EmployeeID)</query>
        <parameters>
            <EmployeeID dd="Employees.EmployeeID" dt="i4"/>
        </parameters>
    </constructor>
</implementation>


Since EmployeeID is the primary key in the above method, its implementation will retrieve employee records that have IDs greater than the given employee ID.

The following is the implementation of the above method that retrieves the previous set of records.

Implementation of GetPreviousEmployeesObjects
<implementation xmlns="" type="DBSQL">
   <constructor language="DBSQL">
       <query>select * from Employees where  (EmployeeID<:EmployeeID) ORDER BY
EmployeeID DESC</query>
       <parameters>
           <EmployeeID dd="Employees.EmployeeID" dt="i4"/>
       </parameters>
   </constructor>
</implementation>


If a request is available for an XForm for which the model is set as automatic, the request is fired when the XForm is opened in the browser. If the request is for retrieving the next set of records, the parameters are assigned the lowest possible values. If the request is for retrieving the previous set of records, the parameters are assigned the highest possible values. However, if the request to retrieve the next set of records is fired when records are already available in the browser, the parameters are assigned the highest values available in the browser. If the request to retrieve the previous set of records is fired when records are already available in the browser, the parameters are assigned the lowest values available in the browser.

The following is the implementation of the method for searching a object.

<implementation type="DBSQL" xmlns="">
    <constructor language="DBSQL">
        <query>select * from Employees where EmployeeID=:EmployeeID</query>
        <parameters>
            <EmployeeID dd="Employees.EmployeeID" dt="i4"/>
        </parameters>
    </constructor>
</implementation>


The above implementation retrieves the object being searched for or gives a blank response if the object is not found.

When searching for an object, the model searches within the already retrieved objects, if any. If the object is not found within the retrieved objects, all three types of requests are made to the server. If no object is found, the object closest to it is retrieved.

Properties, Events, and Methods

Table 1. List of Properties

Design-time property

Run-time property

Description

Model ID

id

Sets the string that identifies the model on a XForm.

Automatic

 

Denotes whether the model automatically sends request and receives data from the server once the XForm is loaded. When not selected, requests have to be fired explicitly using the reset() method. For all models that are transactional and have a Web service interface, it is checked by default.

Non-transactional

nontransactional

Denotes whether a model is non-transactional. For web services other than the Process Platform methods and Web service interfaces, it is checked by default.

WS-AppServer Integration

 

Denotes whether the model is enabled for integration with the business logic provider. When checked, the business logic written through Cordys WS-AppServer will be applied on the data passing through or retrieved using the model.

Instance Schema

 

Sets the schema instance for the data shown on the model. XML instance schema can be set for the model through this property and can be used for Reference selection and automatic validation.

Prompt To Save

promptTosave

Denotes whether a prompt to save unsaved data will display when you edit data on a model and close the XForm. By default, it is checked.

Business Object

 

Sets the name of the root XML data node ( Business Object ) that its data model represents. This will be used when inserting new data into the model's dataset.

Iterator Size

 

Sets the cursor (cache) size of the dataset fetched from the server (application service). The value set here determines the number of records retrieved by the application server from the database before returning to the requested client. By default, the value is 50.

Get Method Name

 

Sets the name of the GET method on the data model, using which a specific record is retrieved by the model from the server. It is mandatorily required by models to retrieve data. The value can be set from Process Platform Web service interfaces and Web service operations accessible by clicking on the lookup button next to the Get Method Name field. The value is deleted by clicking to the lookup button.

Next Method Name

 

Sets the name of the NEXT Web service operation on the data model, using which the next set of records from the current position is retrieved by the model. As in the GET Web service operation, lookup button can be used to select the value, and delete button to make it empty.

Previous Method Name

 

Sets the name of the PREVIOUS Web service operation on the data model, using which previous set of records from the current position are retrieved. As above, lookup button can be used to select the value, and delete button to remove data from make it.

Namespaces

 

Denotes the default namespace URI and all the other namespaces and their prefixes found on the current Web service operation set on the model. The namespaces always denotes GET Web service operation by default and remains empty if not present. While there might be 0 or more prefixes and namespaces, a default namespace will always be presented for any Web Service.

Parent Model

 

Sets the parent model to which the current model is associated. Data models can be associated by relating the parameters of the current models to the fields available on the parent model. The table below this property displays the Request parameter and Fields (of the current model) and the Fields of the parent model using which Associations can be made.

Gateway URL

 

Gateway URL Sets the URL of the gateway to which all the requests are sent from the model to fetch or synchronize data. By default this will point to Cordys's Gateway (com.eibus.web.soap.Gateway.wcp), while for non-transactional models, this will be the binding point specified on the WSDL of the Web service operation.

Receiver

 

Sets the distinguished name (dn) of the Service (SOAP Node or SOAP Processor) to which the Gateway forwards all requests sent by model.

Timeout

 

Sets the duration (milliseconds) for which the Web Server should wait to receive the response from the underlying service provider. By default this is 30000 milliseconds.

Apply Access Control

 

Denotes whether the access modes (Enable, Disable, or Hide) from the business logic specified by WS-AppServer can be applied on the data retrieved by the model. This property is available when WS-AppServer Integration is enabled for the model.

Initialization Required

 

Denotes whether initialization related business logic specified on the WS-AppServer level can be applied when new data is inserted on the model. This property is available when WS-AppServer Integration is enabled for the model.

Constraint Validation

 

Denotes whether business logic constraints set on WS-AppServer need to be applied and model data validated whenever a change occurs on it. This property is available when WS-AppServer Integration is enabled for the model.

Model Messages

 

Sets validation messages specific to the model related activities. Using this, you can customize the default validation messages thrown by the data model (for example, Delete Confirmation).

 

instance

Retrieves the instance object of the data model which contains the meta information for fetching and managing data.

 

soapFaultOccured

Retrieves the boolean value indicating the state of transaction on a data model. If the transaction done to server succeeds, the value will be TRUE, otherwise will be FALSE. This value is updated every time the data on the model is synchronized with the server.

Table 2. List of Events

Event

Description

Change

This event is activated when you change data in the model.

Delete

This event is activated before deleting the business object from the model data after deleting the associated UI.

Insert

This event is activated when the business object is created but before the values are bound to the control.

On After Change

This event is activated after data is changed on the model.

On After Delete

This event is activated after the business object is deleted from the model data.

On After EBI Validate

This event is activated after constraint validation has been carried out with the WS AppServer.

On After Insert

This event is activated after the business object is created in the model data.

On Before Change

This event is activated before the data is changed on the model.

On Before Delete

This event is activated before a business object is deleted from the model data.

On Before EBI Validate

This event is activated before constraint validation has been carried out with the WS AppServer.

On Before Insert

This event is activated before inserting a new business object on the model.

On Before Synchronized

This event is activated before the business object (so changed) in the HTML is synchronized with the database.

On Data Completed

This event is activated after all the views are initialized and the data is rendered.

On Find

This event is activated on searching a business object in the data set of the model.

On Request

This event is activated before the request objects are fired to the backend for retrieving data.

On Response

This event is activated when the model receives a SOAP response from the Gateway.

On Soapfault

This event is activated when a SOAP-fault message is received as the response to a request sent to the backend.

On Synchronized

This event is activated after the changed business object in the control is synchronized with the database.

Table 3. List of Methods

Method

Description

addListener(sEventName, fpFunction) This method registers a function with the model in order to receive notifications for the specified event.

clear()

This method clears the data in the model.

edit(oBusinessObject)

This method returns the appropriate business object for editing.

find (aParameters, oRequest, sScope, bFindIfModified)

This method searches for business objects in the model.

getActiveBusinessObject()

This method retrieves the current business object.

getAllDataset ()

This method sends the Get/Next request to the application service without any cursor.

getData ()

This method returns the data currently available in the model.

getDataset ()

This method sends the Get request of the model to the application service and retrieves the specific business object. It is a subset of the reset() method.

getEBIAccessControl()

This method retrieves the value that denotes whether the access controls (Enable, Disable, or Hide) have been applied on the views of the model based on the logic of the WS AppServer.

getEBIConstraintValidation()

This method retrieves the value that denotes whether the WS-AppServer validation for the constraints have been carried out.

getEBIInitializationRequired()

This method retrieves the value that denotes whether the views of the model have been initialized with the default values from the Process Platform WS AppServer.

getMethodRequest(sMethodType)

This method returns the request of the method corresponding to the type passed as the parameter.

getTransactionState()

This method is no longer supported. The soapFaultOccured property can be used instead of this method.It returns the current state of transaction in a model. This will be useful to know whether the transaction has been successful or not. If it returns True, it has been successful.

isEBIModel()

This method retrieves the value that denotes the WS AppServer Integration for the model.

makeAndSetRequest(sMethodName, sRequestNamespace, aParameters, sMethodType)

This method creates a request at runtime and sets the request as the specified method to the model.

putData(oData[, bRefreshRenderer][,sSearchPath][,bClearData])

This method assigns the provided data to the model.

refreshAllViews()

This method refreshes all the views of the model with the latest data available in the model.

registerAssociatedModel(oAssociatedModel, aRefArray)

This method registers the oAssociatedModel associated model, with a collection of models associated with the current model.

registerUIComponent(oComponent)

This method registers a control with this model.

removeListener(sEventName, fpFunction)

This method unregisters a function from the model so that the function stops receiving notifications for the specified event.

reset ()

This method invokes the correct method (previous or next) to be executed at runtime.

setAsEBIModel(bValue)

This method sets the value to denote the WS AppServer Integration for the model.

setEBIAccessControl(bvalue)

This method sets the value to denote whether the access controls (Enable, Disable, or Hide) will be applied on the views of the model based on the logic of the WS AppServer.

setEBIConstraintValidation(bValue)

This method sets the value to denote whether the WS AppServer validation for the constraints will be carried out.

setEBIInitializationRequired(bValue)

This method sets the value to denote whether the views of the model can be initialized with the default values from Cordys WS-AppServer.

setGateway(sGateway)

This method sets the Gateway property of the model object.

setGetDatasetRequest(oRequest[, oApplicationData])

This method has been deprecated. Use the setMethodRequest() method instead. It sets the request for the Get() method.

setMethodRequest(oRequest, sMethodType)

This method sets the provided request to the model.

setNextDatasetRequest(oRequest[, oApplicationData])

This method has been deprecated. Use the setMethodRequest() method instead. Sets the request for the Next method, which retrieves the next set of business objects.

setPreviousDatasetRequest( oRequest[, oApplicationData])

This method has been DEPRECATED. Use the setMethodRequest() method instead. It sets the request for the Previous method, which retrieves the next set of business objects.

setNamespaceWithPrefix(prefix, namespaceURI)

Sets the namespace with prefix on the model. This method is used in runtime when the data with different namespaces is supplied from different documents to the single model.

synchronize(bRefresh)

This method sends an update request to the application service.

synchronizeAssociatedModel()

This method sends an update request and synchronizes the specified associated model according to its current active business object.

synchronizeAssociatedModels()

This method sends an update request and synchronizes all associated models according to the active business object of the current model.

undo()

This method works at the data level. It aids with the programming procedure such that you can code without worrying about the content or control being dealt with.

unedit(oBusinessObject)

This method reverts the changes made to the specified business object.

validateEBIConstraints(cTupleCollection)

This method executes the WS AppServer logic for validating the constraints on the data in the collection of tuples passed to the server.

 

Related reference

Business Object
Transactional and Non-transactional Data
putData()
Setting Data For Models
setMethodRequest()
reset()
Retrieving Data For Models
Instance
getInstance()
getModel()
Non-transactional - nontransactional (Model)
Model
size